unit drawQC;

interface

uses 
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  TeEngine, Series, ExtCtrls, TeeProcs, Chart;

type
  TdrawQcfrm = class(TFrame)
    QcChat: TChart;
    trays: TLineSeries;
    weight: TLineSeries;
  private
    { Private declarations }
  public
    { Public declarations }
    function getChatData(rfid:String;dttim:TDateTime):Boolean;
  end;

implementation

uses dbmodule, includefile;

{$R *.dfm}

function TdrawQcfrm.getChatData(rfid:String;dttim:TDateTime):Boolean;
var
  tmpTrays,tmpWeight:Real;
  pickername:string;
begin
  QcChat.Refresh; 
  tmpTrays:=0;
  tmpWeight:=0;
  weight.Clear;
  trays.Clear;
  with dbmodulefrm.dbtmpqryEx do begin
    active:=False;
    sql.clear;
    sql.Add('SELECT RECORD.DATETIME As TIM, RECORD.NW As NW, RECORD.TRAYS As Tray, EMPLOYEE.NAME As [Name] FROM RECORD,EMPLOYEE');
    SQL.Add('WHERE RECORD.RFID=EMPLOYEE.RFID');
    SQL.Add(Format('AND RECORD.DATETIME>=#%s#',[FormatDateTime('YYYY-MM-DD',dttim)]));
    SQL.Add(Format('AND RECORD.DATETIME<#%s#',[FormatDateTime('YYYY-MM-DD',dttim+1)]));
    sql.Add(Format('AND Right(RECORD.RFID,%d)=''%s''',[RFIDLEN,rfid]));
    Sql.Add('Order By RECORD.DATETIME');
    execsql;
    active:=True;
    pickername:=FieldByName('Name').AsString;
    first;
    while not eof do begin
      tmpTrays:= tmpTrays+FieldByName('Tray').AsFloat;
      tmpWeight:=tmpWeight+FieldByName('NW').AsFloat;
      weight.AddXY(FieldByName('TIM').AsDateTime,tmpWeight);
      Trays.AddXY(FieldByName('TIM').AsDateTime,tmpTrays);
      next;
    end; 
    Active:=False;
  end;
  QcChat.Title.Text.Clear;
  QcChat.Foot.Text.Clear;
  QcChat.Title.Text.Add(Format('  RFID:%-10s Name:%-20s',[rfid,pickername]));
  QcChat.Title.Text.Add(Format('  Date:%s',[FormatDateTime(DateFrtStr,dttim)]));
  QcChat.Foot.Text.Add(Format('  Total: wt=%f (kg)  Trays=%d',[tmpWeight,round(tmpTrays)]));
  try
    QcChat.Foot.Text.Add(Format('  Average=%f (kg/tray)',[tmpWeight/tmpTrays]));
  except end;
end;

end.
